1. What's a process
  2. How are processes represented by OS's
  3. How are multi concurrent processes managed by OS's

Process :

Instance of executing program. Synonymous with "task" or "job".

Including:

  1. State of execution: program, counter, stack
  2. Parts & temporary holding area: data, register state, occupies state in memory
  3. May require special hardware: I/O devices

OS manages hardware on behalf of applications.

Application: A static entity. Program on disk, flash memory.

Process: An active entity. State of a program when executing, loaded in the memory.

Types of state

  1. Text & Data: static state when process first loads ($V_0$)
  2. heap: dynamically created during execution
  3. stack: dynamical part of address space, which grows and shrinks in a LIFO order ($V_{max}$). e.g. store states.

Address space:

  1. Virtual addresses
  2. In memory representation of a process. Not corresponding with actual physical addresses. Don't need to be continous.
  3. Page tables: mapping of virtual to actual address (in memoery or on desk)
  4. Parts of virtual address space may not be allocated. The other may be on the disk.
  5. May not be enough physical memory for all states

image.png

How does the OS know what a process is doing.

State of process:

Program counter (PC):

  1. At anytime, CPU need to know where in the instruction sequence (binary) the process is currently is.
  2. Maintained on the CPU while the CPU is executing in the register

Register: Hold values necessary on CPU during the execution like addresses for state, status information, etc.

Stack pointer: define process stack. Retrive what's on the top of the stack first (LIFO)

Process Control Block (PCB):

  1. Data structure that an OS maintians for every one of the processes it manages.
  2. Created and initialized when a process is created
  3. Ceratin fields are updated when process state changes
  4. For performance reasons, CPU has register and automatically update for frequently changed fields like program counter which changes for every instruction.
  5. It's OS's job to collection all information CPU maintains for process and store it in PCB when the process is no longer running on the CPU.

Including:

  1. Process state
  2. Process number
  3. Process counter
  4. Registers
  5. Memory limits
  6. List of open files
  7. Priority
  8. Signal mask
  9. CPU scheduling information
  10. Memory mapping
  11. etc

context switch

  1. Switching the CPU from the context of one process to the context of another.
  2. Can be expensive
    1. Direct costs: number of cycles for loading & storing instructions to & from memeory
    2. Indirect costs: data stored in cache hiarachy, which is much faster than memory (hot cache). Switching to another process causes COLD cache or cache misses.
  3. Limit the frequency of context switch

image.png

Process lifecycle

image.png

image.png

Process Creation

Mechanism for process creation

  1. Fork: copy the parent PCB into new child PCB
  2. Exec: replace child image, load new program and start from first instruction

image.png

CPU Scheduler

determins which one of the currently ready processes will be dispatched to the CPU to start running, and how long it should run for.

OS must

  1. preempt: interrupt and save current context
  2. schedule: run scheduler to choose next process
  3. dispatch: dispatch process & switch into its context
  4. minimize these tasks to be efficient

image.png

image.png

Inter Process Communication (IPC)

  1. transfer data/information between address space
  2. maintain protection and isolation
  3. provide flexcibility and performance

Message Passing IPC

  1. OS provides communication channel, like shared buffer.
  2. Process can write/send or read/receive message to/from the buffer.
  3. Pros: OS managed.
  4. Cons: expensive overheads.

Shared Memory IPC

  1. OS establishes a shared channel and maps it into each process address space.
  2. Processes directly read/write from this memory.
  3. Pros: OS is out of the way
  4. Cons: reimpliment code

image.png